package com.wjx.demo.condition

fun main(args: Array<String>) {
    val a = 1
    var b = 3
    if (a > b) println(a) else println(b)
    var max = if (a > b) {
        print("a")
        a
    } else {
        print("b")
        b
    }
    println(max)

    //in 区间
    if (a in 1..4) {
        println(true)
    } else {
        false
    }

    //when

    when (a) {
        1 -> println(1)
        2 -> println(2)
        else -> {
            println(3)
        }
    }

    when (a) {
        1, 2 -> println("1,2")
        else -> println("else")
    }

    var arr = arrayOf(0, 1)
    when (a) {
        in arr -> println("0,1")
        !in 0..1 -> println("!0,1")
        else -> {
            println("else")
        }
    }

    fun hasPrefix(x: Any) = when (x) {
        is String -> x.startsWith("prefix")
        else -> false
    }
    println(hasPrefix("1"))

    var x = 1
    when {
        x > 1 -> println(">1")
        x == 1 -> println("=1")
        else -> println("<1")
    }
}